package com.hwzn.module.front.controller.admin;

import static com.hwzn.module.core.pojo.CommonResult.success;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hwzn.module.admin.service.AuthService;
import com.hwzn.module.admin.service.UserService;
import com.hwzn.module.core.dos.UserDO;
import com.hwzn.module.core.pojo.CommonResult;
import com.hwzn.module.core.vos.AuthLoginReqVO;
import com.hwzn.module.core.vos.AuthLoginRespVO;
import com.hwzn.module.core.vos.AuthRegisterReqVO;

/**
 * 主类
 *
 * @author jiaobo
 * @date Created in 2024/5/15 11:21
 * @company hw
 **/
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Resource
    private UserService userService;

    @Resource
    private AuthService authService;

    @PostMapping("/login")
    public CommonResult<AuthLoginRespVO> login(@RequestBody AuthLoginReqVO reqVO) {
        AuthLoginRespVO login = authService.login(reqVO);
        return success(login);
    }

    @PostMapping("/register")
    public CommonResult<Boolean> register(@RequestBody AuthRegisterReqVO reqVO) {
        authService.register(reqVO);
        return success(true);
    }

    @RequestMapping("/getUser")
    public CommonResult<UserDO> getUser(@RequestParam("id") Long id) {
        UserDO userById = userService.getUserById(id);
        return success(userById);
    }

    @RequestMapping("/test")
    public CommonResult<Boolean> test() {
        userService.test();
        return success(true);
    }

}
